package com.example.mycontentprovider;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //如果表info中没有记录，则项该表中插入2条记录
        MyDBHelper myDBHelper=new MyDBHelper(this);
        SQLiteDatabase db=myDBHelper.getWritableDatabase();
        Cursor cursor=db.query("info",null,null,null,null,null,null);
        if(cursor.getCount()==0){         //如果记录数为0，则插入2条记录
            for(int i=1;i<3;i++){
                ContentValues values=new ContentValues();
                values.put("name","UserName"+i);
                values.put("age",20+i);
                db.insert("info",null,values);
            }
        }
        cursor.close();
        db.close();
    }
}
